(function(){"use strict";BX.namespace("BX.Grid");BX.Grid.ActionPanel=function(t,e,n){this.parent=null;this.rel={};this.actions=null;this.types=null;this.lastActivated=[];this.init(t,e,n)};BX.Grid.ActionPanel.prototype={init:function(parent,actions,types){this.parent=parent;this.actions=eval(actions);this.types=eval(types);BX.addCustomEvent(window,"Dropdown::change",BX.proxy(function(t,e,n,a){this.isPanelControl(BX(t))&&this._dropdownChange(t,e,n,a)},this));BX.addCustomEvent(window,"Dropdown::load",BX.proxy(function(t,e,n,a){this.isPanelControl(BX(t))&&this._dropdownChange(t,e,n,a)},this));var panel=this.getPanel();BX.bind(panel,"change",BX.delegate(this._checkboxChange,this));BX.bind(panel,"click",BX.delegate(this._clickOnButton,this));BX.addCustomEvent(window,"Grid::updated",function(){var t=BX("grid_cancel_button");t&&BX.fireEvent(BX.firstChild(t),"click")})},resetForAllCheckbox:function(){var t=this.getForAllCheckbox();if(BX.type.isDomNode(t)){t.checked=null}},getForAllCheckbox:function(){return BX.Grid.Utils.getByClass(this.getPanel(),this.parent.settings.get("classForAllCheckbox"),true)},getPanel:function(){return BX.Grid.Utils.getByClass(this.parent.getContainer(),this.parent.settings.get("classActionPanel"),true)},getApplyButton:function(){return BX.Grid.Utils.getByClass(this.getPanel(),this.parent.settings.get("classPanelApplyButton"),true)},isPanelControl:function(t){return BX.hasClass(t,this.parent.settings.get("classPanelControl"))},getTextInputs:function(){return BX.Grid.Utils.getBySelector(this.getPanel(),'input[type="text"]')},getHiddenInputs:function(){return BX.Grid.Utils.getBySelector(this.getPanel(),'input[type="hidden"]')},getSelects:function(){return BX.Grid.Utils.getBySelector(this.getPanel(),"select")},getDropdowns:function(){return BX.Grid.Utils.getByClass(this.getPanel(),this.parent.settings.get("classDropdown"))},getCheckboxes:function(){return BX.Grid.Utils.getByClass(this.getPanel(),this.parent.settings.get("classPanelCheckbox"))},getButtons:function(){return BX.Grid.Utils.getByClass(this.getPanel(),this.parent.settings.get("classPanelButton"))},isDropdown:function(t){return BX.hasClass(t,this.parent.settings.get("classDropdown"))},isCheckbox:function(t){return BX.hasClass(t,this.parent.settings.get("classPanelCheckbox"))},isTextInput:function(t){return t.type==="text"},isHiddenInput:function(t){return t.type==="hidden"},isSelect:function(t){return t.tagName==="SELECT"},createDropdown:function(t,e){var n=this.createContainer(t.ID,e);var a=BX.create("div",{props:{className:"main-dropdown main-grid-panel-control",id:t.ID+"_control"},attrs:{name:t.NAME,"data-name":t.NAME,"data-items":JSON.stringify(t.ITEMS),"data-value":t.ITEMS[0].VALUE,"data-popup-position":"fixed"},children:[BX.create("span",{props:{className:"main-dropdown-inner"},html:t.ITEMS[0].NAME})]});n.appendChild(a);return n},createCheckbox:function(t,e){var n=this.createContainer(t.ID,e);var a=BX.create("span",{props:{className:"main-grid-checkbox-container"}});var i=BX.create("span",{props:{className:"main-grid-control-panel-content-title"}});var r=BX.create("input",{props:{type:"checkbox",className:this.parent.settings.get("classPanelCheckbox")+" main-grid-checkbox",id:t.ID+"_control"},attrs:{value:t.VALUE||"",title:t.TITLE||"",name:t.NAME||"","data-onchange":JSON.stringify(t.ONCHANGE)}});r.checked=t.CHECKED||null;n.appendChild(a);n.appendChild(i);a.appendChild(r);a.appendChild(BX.create("label",{props:{className:"main-grid-checkbox"},attrs:{for:t.ID+"_control",title:t.TITLE}}));i.appendChild(BX.create("label",{attrs:{for:t.ID+"_control",title:t.TITLE},html:t.LABEL}));return n},createText:function(t,e){var n=this.createContainer(t.ID,e);var a=BX.type.isNotEmptyString(t["TITLE"])?t["TITLE"]:"";if(a!==""){n.appendChild(BX.create("label",{attrs:{title:a,for:t.ID+"_control"},text:a}))}n.appendChild(BX.create("input",{props:{className:"main-grid-control-panel-input-text main-grid-panel-control",id:t.ID+"_control"},attrs:{name:t.NAME,title:a,placeholder:t.PLACEHOLDER||"",value:t.VALUE||"",type:"text","data-onchange":JSON.stringify(t.ONCHANGE||[])}}));return n},createHidden:function(t,e){var n=this.createContainer(t.ID,e);n.appendChild(BX.create("input",{props:{id:t.ID+"_control",type:"hidden"},attrs:{name:t.NAME,value:t.VALUE||""}}));return n},createButton:function(t,e){var n=this.createContainer(t.ID,e);var a=BX.create("button",{props:{className:"main-grid-buttons"+(t.CLASS?" "+t.CLASS:""),id:t.id+"_control",title:BX.type.isNotEmptyString(t.TITLE)?t.TITLE:""},attrs:{name:t.NAME||"","data-onchange":JSON.stringify(t.ONCHANGE||[])},html:t.TEXT});n.appendChild(a);return n},createLink:function(t,e){var n=this.createContainer(t.ID,e);var a=BX.create("a",{props:{className:"main-grid-link"+(t.CLASS?" "+t.CLASS:""),id:t.ID+"_control"},attrs:{href:t.HREF||"","data-onchange":JSON.stringify(t.ONCHANGE||[])},html:t.TEXT});n.appendChild(a);return n},createCustom:function(t,e){var n=this.createContainer(t.ID,e);var a=BX.create("div",{props:{className:"main-grid-panel-custom"+(t.CLASS?" "+t.CLASS:"")},html:t.VALUE});n.appendChild(a);return n},createContainer:function(t,e){t=t.replace("_control","");e=e.replace("_control","");return BX.create("span",{props:{className:this.parent.settings.get("classPanelControlContainer"),id:t},attrs:{"data-relative":e}})},removeItemsRelativeCurrent:function(t){var e=t;var n=t.id;var a=[];var i;while(e){i=BX.data(e,"relative");if(i===n||i===t.id){n=e.id;a.push(e)}e=e.nextElementSibling}a.forEach(function(t){BX.remove(t)})},validateData:function(t){return"ONCHANGE"in t&&BX.type.isArray(t.ONCHANGE)},activateControl:function(t){var e=BX(t);if(BX.type.isDomNode(e)){BX.removeClass(e,this.parent.settings.get("classDisable"));e.disabled=null}},deactivateControl:function(t){var e=BX(t);if(BX.type.isDomNode(e)){BX.addClass(e,this.parent.settings.get("classDisable"));e.disabled=true}},showControl:function(t){var e=BX(t);e&&BX.show(e)},hideControl:function(t){var e=BX(t);e&&BX.hide(e)},validateActionObject:function(t){return BX.type.isPlainObject(t)&&"ACTION"in t&&BX.type.isNotEmptyString(t.ACTION)&&(t.ACTION===this.actions.RESET_CONTROLS||"DATA"in t&&BX.type.isArray(t.DATA))},validateControlObject:function(t){return BX.type.isPlainObject(t)&&"TYPE"in t&&"ID"in t},createDate:function(t,e){var n=this.createContainer(t.ID,e);var a=BX.decl({block:"main-ui-date",mix:["main-grid-panel-date"],calendarButton:true,valueDelete:true,placeholder:"PLACEHOLDER"in t?t.PLACEHOLDER:"",name:"NAME"in t?t.NAME+"_from":"",tabindex:"TABINDEX"in t?t.TABINDEX:"",value:"VALUE"in t?t.VALUE:"",enableTime:"TIME"in t?t.TIME?"true":"false":"false"});n.appendChild(a);return n},createControl:function(t,e){var n=null;switch(t.TYPE){case this.types.DROPDOWN:n=this.createDropdown(t,e);break;case this.types.CHECKBOX:n=this.createCheckbox(t,e);break;case this.types.TEXT:n=this.createText(t,e);break;case this.types.HIDDEN:n=this.createHidden(t,e);break;case this.types.BUTTON:n=this.createButton(t,e);break;case this.types.LINK:n=this.createLink(t,e);break;case this.types.CUSTOM:n=this.createCustom(t,e);break;case this.types.DATE:n=this.createDate(t,e);break}return n},onChangeHandler:function(container,actions,isPseudo){var newElement,callback;var self=this;if(BX.type.isDomNode(container)&&BX.type.isArray(actions)){actions.forEach(function(action){if(self.validateActionObject(action)){if(action.ACTION===self.actions.CREATE){self.removeItemsRelativeCurrent(container);action.DATA.reverse();action.DATA.forEach(function(t){if(self.validateControlObject(t)){newElement=self.createControl(t,BX.data(container,"relative")||container.id);if(BX.type.isDomNode(newElement)){BX.insertAfter(newElement,container);if("ONCHANGE"in t&&t.TYPE===self.types.CHECKBOX&&"CHECKED"in t&&t.CHECKED){self.onChangeHandler(newElement,t.ONCHANGE)}if(t.TYPE===self.types.DROPDOWN&&BX.type.isArray(t.ITEMS)&&t.ITEMS.length&&"ONCHANGE"in t.ITEMS[0]&&BX.type.isArray(t.ITEMS[0].ONCHANGE)){self.onChangeHandler(newElement,t.ITEMS[0].ONCHANGE)}}}})}if(action.ACTION===self.actions.ACTIVATE){self.removeItemsRelativeCurrent(container);if(BX.type.isArray(action.DATA)){action.DATA.forEach(function(t){self.lastActivated.push(t.ID);self.activateControl(t.ID)})}}if(action.ACTION===self.actions.SHOW){if(BX.type.isArray(action.DATA)){action.DATA.forEach(function(t){self.showControl(t.ID)})}}if(action.ACTION===self.actions.HIDE){if(BX.type.isArray(action.DATA)){action.DATA.forEach(function(t){self.hideControl(t.ID)})}}if(action.ACTION===self.actions.HIDE_ALL_EXPECT){if(BX.type.isArray(action.DATA)){(self.getControls()||[]).forEach(function(t){if(!action.DATA.some(function(e){return e.ID===t.id})){self.hideControl(t.id)}})}}if(action.ACTION===self.actions.SHOW_ALL){(self.getControls()||[]).forEach(function(t){self.showControl(t.id)})}if(action.ACTION===self.actions.REMOVE){if(BX.type.isArray(action.DATA)){action.DATA.forEach(function(t){BX.remove(BX(t.ID))})}}if(action.ACTION===self.actions.CALLBACK){this.confirmDialog(action,BX.delegate(function(){if(BX.type.isArray(action.DATA)){action.DATA.forEach(function(currentCallback){if(currentCallback.JS.indexOf("Grid.")!==-1){callback=currentCallback.JS.replace("Grid","self.parent");callback=callback.replace("()","");callback+=".apply(self.parent, [container])";try{eval(callback)}catch(t){throw new Error(t)}}else if(BX.type.isNotEmptyString(currentCallback.JS)){try{eval(currentCallback.JS)}catch(t){throw new Error(t)}}})}},this))}if(action.ACTION===self.actions.RESET_CONTROLS){this.removeItemsRelativeCurrent(container)}}},this)}else{if(!isPseudo){this.removeItemsRelativeCurrent(container)}self.lastActivated.forEach(function(t){self.deactivateControl(t)});self.lastActivated=[]}},confirmDialog:function(t,e,n){this.parent.confirmDialog(t,e,n)},_dropdownChange:function(t,e,n,a){var i=BX(t);var r=i.parentNode;var s=a&&"ONCHANGE"in a?a.ONCHANGE:null;var o=a&&("PSEUDO"in a&&a.PSEUDO!==false);this.onChangeHandler(r,s,o)},_checkboxChange:function(event){var onChange;try{onChange=eval(BX.data(event.target,"onchange"))}catch(t){onChange=null}this.onChangeHandler(BX.findParent(event.target,{className:this.parent.settings.get("classPanelContainer")},true,false),event.target.checked||event.target.id.indexOf("actallrows_")!==-1?onChange:null)},_clickOnButton:function(event){var onChange;if(this.isButton(event.target)){event.preventDefault();try{onChange=eval(BX.data(event.target,"onchange"))}catch(t){onChange=null}this.onChangeHandler(BX.findParent(event.target,{className:this.parent.settings.get("classPanelContainer")},true,false),onChange)}},isButton:function(t){return BX.hasClass(t,this.parent.settings.get("classPanelButton"))},getSelectedIds:function(){var t=this.parent.getRows().getSelected().filter(function(t){return t.isShown()});return t.map(function(t){return t.getId()})},getControls:function(){return BX.findChild(this.getPanel(),{className:this.parent.settings.get("classPanelControlContainer")},true,true)},getValues:function(){var t={};var e=this;var n=[].concat(this.getDropdowns(),this.getTextInputs(),this.getHiddenInputs(),this.getSelects(),this.getCheckboxes(),this.getButtons());(n||[]).forEach(function(n){if(BX.type.isDomNode(n)){if(e.isDropdown(n)){var a=BX.data(n,"value");a=a!==null&&a!==undefined?a:"";t[BX.data(n,"name")]=a}if(e.isSelect(n)){t[n.getAttribute("name")]=n.options[n.selectedIndex].value}if(e.isCheckbox(n)&&n.checked){t[n.getAttribute("name")]=n.value}if(e.isTextInput(n)||e.isHiddenInput(n)){t[n.getAttribute("name")]=n.value}if(e.isButton(n)){var i=BX.data(n,"name");var r=BX.data(n,"value");r=r!==null&&r!==undefined?r:"";if(i){t[i]=r}}}});return t}}})();
//# sourceMappingURL=action-panel.map.js